<?php $this->fetch('public/head'); ?>
<!--tab标签-->
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">后台菜单</li>
        <li class=""><a href="<?php echo url('hsmenu/add') ?>">添加菜单</a></li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table class="layui-table">
                <thead>
                <tr>
                    <th style="width: 60px;">展开</th>
                    <th style="width: 50px;">排序</th>
                    <th style="width: 30px;">ID</th>
                    <th>菜单名称</th>
                    <th>控制器方法</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach($admin_menu_level_list as $v){?>
                <tr class="level_<?php echo $v['level']==1?'one':($v['level']==2?'two':'three') ?> level_<?php echo $v['pid'] ?>"  data-id="<?php echo $v['id'] ?>" data-pid="<?php echo $v['pid'] ?>" style="">
                    <?php $url = url('hsmenu/setStatus?id='.$v['id']) ?>
                    <td <?php if($v['son']){echo 'class="open_level"';} ?>><?php echo str_repeat('&nbsp;',($v['level']-1)*2) ?><i class="layui-icon" data-id="<?php echo $v['id'] ?>" style="font-size: 25px;<?php if(!$v['son']){echo 'color: #ccc;';} ?>">&#xe623;</i></td>
                    <td>
                        <input class="layui-input" name="sort" required="" lay-verify="required" placeholder="" autocomplete="off" type="text" id="change_sort_<?php echo $v['id'] ?>" value="<?php echo $v['sort'] ?>" data-url="<?php echo $url ?>" onchange="change_sort(<?php echo $v['id'] ?>)">
                    </td>
                    <td><?php echo $v['id'] ?></td>
                    <td><?php echo $v['level']>1?str_repeat('&nbsp;&nbsp;&nbsp;└─',$v['level']-1):'',$v['title'] ?></td>
                    <td><?php echo $v['name'] ?></td>
                    <td>
                    	<?php if($v['status']==1): ?>
                    	<a href="<?php echo $url ?>" data-param="status=0" class="layui-btn layui-btn-xs ajax-post">显示</a>
                    	<?php else: ?>
                    	<a href="<?php echo $url ?>" data-param="status=1" class="layui-btn layui-btn-danger layui-btn-xs ajax-post">隐藏</a>
                    	<?php endif; ?>
                    </td>
                    <td>
                        <a href="<?php echo url('hsmenu/add?pid='.$v['id']) ?>" class="layui-btn layui-btn-xs">添加子菜单</a>
                        <a href="<?php echo url('hsmenu/edit?id='.$v['id']) ?>" class="layui-btn layui-btn-normal layui-btn-xs">编辑</a>
                        <a href="<?php echo url('hsmenu/delete?id='.$v['id']) ?>" class="layui-btn layui-btn-danger layui-btn-xs ajax-delete">删除</a>
                    </td>
                </tr>
               	<?php } ?>
                </tbody> 
            </table>
        </div>
    </div>
</div>

<?php $this->fetch('public/script'); ?>
<script src="_js/menu.js"></script>
<script>
//修改排序值
function change_sort(id){
    var sort = $("#change_sort_"+id).val();
    var _url = $("#change_sort_"+id).attr("data-url");
    $.ajax({
        type:'POST',
        url:_url,
        dataType: "json",
        data:{"sort":sort},
        success:function(info){
            if (info.code === 1) {
                setTimeout(function () {
                    location.href = info.url;
                }, 1000);
            }
            layer.msg(info.msg);
        }
    })
}
</script>